import { api } from '../boot/axios'
import { RepairOrderTask } from './type'

function url(s: string) {
  return ['/api/repairordertasks', s.replace('/', ''), ''].join('/')
}


export async function getRepairOrderTasks(repair_order_id:number) {
  const res = await api({
    url: url('get_repair_order_all_tasks'),
    method: 'post',
    data:{
      repair_order_id:repair_order_id
    }
  })

  if (res.data.code==1){
    return res.data.data as RepairOrderTask[]
  }
}

export function bulkUpdateResult(data: {id:number, result:string}[]) {
  return api({
    url: url('bulk_update_result'),
    method: 'post',
    data:{
      update:data
    }
  })
}

export function createOrderTask(orderTask: {
  orderId: number;
  name: string;
  mtce_type?: string;
  cur_tab?: boolean;
  final_tab?: boolean;
  eform_schema_id?: number;
  verify_user_id: number;
  endorse_user_id: number;
}){
  console.log(orderTask,'orderTask');
  let { orderId:order_id, name, mtce_type, cur_tab, final_tab, eform_schema_id, verify_user_id, endorse_user_id} = orderTask || {};
  return api({
    url:url('create_order_task'),
    method: 'post',
    data:{
      order_id,
      name:name,
      mtce_type,
      cur_tab,
      final_tab,
      eform_schema_id,
      verify_user_id,
      endorse_user_id
    }
  })
}

export function fetchRemoveNewAddOrderTask(id: number){
  return api({
    url:url('remove_order_task'),
    method: 'delete',
    data:{
      id
    }
  })
}

export function checkTaskGroup(repair_order_task_id:number) {
  return api({
    url:url('check_task_group'),
    method: 'post',
    data:{
      repair_order_task_id
    }
  })
}